<?php
/**
 * @package    JWPBlog
 * @author David Neimeyer davidneimeyer@gmail.com
 * @link http://indie-bookstore.googlecode.com/
 * @license    GNU/GPL
 */

/** access via Joomla! index only */
defined('_JEXEC') or die('Restricted Access');

jimport( 'joomla.application.component.view');
/*
function jwpautoload($sClass)
{
    try
    {
    	require_once $sClass . '.php';
        //throw new Exception('It works');
    }
    catch (Exception $oException)
    {
        throwAutoloadException($sClass, $oException);
    }
}

function throwAutoloadException($sClass, Exception $oException)
{
    // The use of eval is risky, because it could be easily exploited. To prefend
    // that the use of eval in this method could be exploited we make sure that the
    // variable contains only the allowed characters of a class name.
    if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $sClass))
    {
        eval('class '.$sClass.'
        {
            static public function throwException()
            {
                throw unserialize(\''.serialize($oException).'\');
            }
        }
       
        '.$sClass.'::throwException();');
    }
}
spl_autoload_register('jwpautoload');
*/

/**
 * JWPBlog base view
 *
 */
class JwpblogViewBase extends JView
{
	var $jwpblog_submenu_array = array();
	var $jwpblog_minimenu_array = array();
	
	function init_minimenu(){
		$this->jwpblog_minimenu_array = array(			
				'default'	=> array(),
				'jwpblog'	=> array(),
				'comments'	=> array(),
				'edit'		=> array(),
				'post'		=> array('post','page','link'),
				'help'		=> array(),
			);	
			JwpblogMenuHelper::getInstance('minimenu');	
	}
	
	function submenu($user){
		JSubMenuHelper::addEntry( JText::_( 'Dashboard' ), 'index.php?option=com_jwpblog');
		JSubMenuHelper::addEntry( JText::_( 'Write' ), 'index.php?option=com_jwpblog&controller=post');
		JSubMenuHelper::addEntry( JText::_( 'Manage' ), 'index.php?option=com_jwpblog&controller=edit&view=events');
		JSubMenuHelper::addEntry( JText::_( 'Design' ), 'index.php?option=com_jwpblog&controller=theme&view=venues');
		JSubMenuHelper::addEntry( JText::_( 'Comments' ), 'index.php?option=&controller=comments&view=categories');
		JSubMenuHelper::addEntry( JText::_( 'HELP' ), 'index.php?option=com_jwpblog&view=help');
		if ($user->get('gid') > 24) {
			JSubMenuHelper::addEntry( JText::_( 'SETTINGS' ), 'index.php?option=com_jwpblog&controller=settings&task=edit');
			JSubMenuHelper::addEntry( JText::_( 'PLUGINS' ), 'index.php?option=com_jwpblogt&controller=plugins');
			JSubMenuHelper::addEntry( JText::_( 'USERS' ), 'index.php?option=com_jwpblog&controller=users');
		}		
	}	
		
	function setJwpblogMiniMenu($layout = NULL,$view = NULL,$controller = NULL){
		if(empty($this->jwpblog_minimenu_array)){
			$this->init_minimenu();
		}
		$controller = ($controller)? $controller:$this->getName();
		$view = ($view)? $view : $controller;
		$layout = ($layout)?$layout : $this->getLayout();
		$uri =& JURI::getInstance();
		$uri_array= array(
			'option'		=> 'com_jwpblog',
			'controller'	=> $controller,
			'view'			=> $view,
		);		
		$minimenu = JwpblogMenuHelper::getInstance('minimenu');
		
		foreach($this->jwpblog_minimenu_array[$view] as $menu_item){			
			$uri_array['layout'] = $menu_item;
			$uri->setQuery($uri_array); 
			$active = ($layout == $menu_item)? true : false;
			$minimenu->addEntry(ucfirst($menu_item),$uri->toString(),$active);
		}		
	}
}
?>